//
//  Profile.m
//  A One POS
//
//  Created by AonePOS on 24/09/13.
//  Copyright (c) 2013 AonePOS. All rights reserved.
//

#import "Profile.h"
#import "Settings.h"
#import "Home.h"
#import "Stores.h"
#import "Inventory.h"
#import "Customers.h"
#import "Employees.h"
#import "Reports.h"
#import "Contacts.h"
#import "DataBaseManager.h"
#import "ServersyncClass.h"
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
@interface Profile ()

@end

@implementation Profile
{
    ServersyncClass *serverSyncClassObject;
    general_data *generalDataObject;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    
    generalDataObject =[general_data new];
    [generalDataObject  GetuserDataVariablesMethod];
    serverSyncClassObject=[ServersyncClass new];
    [NSThread detachNewThreadSelector:@selector(ServerSyncronizationMethod) toTarget:serverSyncClassObject withObject:nil];
 
    [super viewDidLoad];
    //[NSThread detachNewThreadSelector:@selector(ServerSyncronizationMethod) toTarget:[ServersyncClass sharedInstance] withObject:nil];
    
  //  admindataArray=[[NSMutableArray alloc]init];
    
     y=0;
    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")){
        y=y+20;
    }
    CGFloat width,height;
    width=768;
    height=1004;
    
  
    backgroundcolorview=[[UIView alloc]init];
    backgroundcolorview.frame=CGRectMake(0,y,width,height-100);
    [backgroundcolorview  setBackgroundColor:[UIColor colorWithPatternImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"background" ofType:@"jpg"]]]];
    
    [self.view addSubview:backgroundcolorview];
 
    
    sidemenu=[[UIView alloc]init];
    sidemenu.frame=CGRectMake(0, 1,170 ,height-150);
    //sidemenu.hidden=YES;
    //[sidemenu  setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"bluecolorstrip.jpg"]]];
    [sidemenu  setBackgroundColor:[UIColor colorWithPatternImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"bluecolorstrip" ofType:@"jpg"]]]];
    
    
    NSString *pagetitle;
    pagetitle=@"Profile";
    
    navBar = [[UINavigationBar alloc] init];
    navBar.frame=CGRectMake(0, 0,width, 50.0);
    
    [navBar setBackgroundImage:[UIImage imageNamed:@"logo-login-bg-short.png"] forBarMetrics:UIBarMetricsDefault];
    
    //[navBar setBackgroundColor:[UIColor blackColor]];
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 50)];
    titleLabel.font=[UIFont boldSystemFontOfSize:30.0];
    titleLabel.textColor = [UIColor blackColor];
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.text =pagetitle;
    [self.navigationItem setTitleView:titleLabel];
    [navBar pushNavigationItem:self.navigationItem animated:false];
    [backgroundcolorview addSubview:navBar];
    
    
    menubutton = [UIButton buttonWithType:UIButtonTypeCustom];
    [menubutton setFrame:CGRectMake(0,0,50,50)];
    [menubutton addTarget:self action:@selector(menuclicked) forControlEvents:UIControlEventTouchUpInside];
    [menubutton setImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"arrow" ofType:@"png"]] forState:UIControlStateNormal];
    [navBar addSubview:menubutton];
   
    logoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [logoBtn setFrame:CGRectMake(60,0,250,50)];
    // [logoBtn addTarget:self action:@selector(menuclicked) forControlEvents:UIControlEventTouchUpInside];
    
    //[logoBtn setImage:[UIImage imageNamed:@"headeraonelogo.png"] forState:UIControlStateNormal];
    [logoBtn setImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"headeraonelogo" ofType:@"png"]] forState:UIControlStateNormal];
    
    [navBar addSubview:logoBtn];
    
    sationLbl=[[UILabel alloc] init];
    sationLbl.frame=CGRectMake(navBar.frame.size.width-280, 5,100, 40);
    [sationLbl setFont:[UIFont systemFontOfSize:13.0f]];
    [sationLbl setBackgroundColor:[UIColor clearColor]];
    [sationLbl setTextColor:[UIColor blackColor]];
    [sationLbl setText:@"Station No:1"];
    sationLbl.lineBreakMode = NSLineBreakByWordWrapping;
    sationLbl.numberOfLines = 2;
    [sationLbl setTextAlignment:NSTextAlignmentLeft];
    [navBar addSubview:sationLbl];
    
    
    EmpIdlbl=[[UILabel alloc] init];
    EmpIdlbl.frame=CGRectMake(navBar.frame.size.width-193, 5,150, 40);
    [EmpIdlbl setFont:[UIFont systemFontOfSize:13.0f]];
    [EmpIdlbl setBackgroundColor:[UIColor clearColor]];
    [EmpIdlbl setTextColor:[UIColor blackColor]];
    [EmpIdlbl setText:[NSString stringWithFormat:@"Employee Id: %@",[generalDataObject  userID]]];
    EmpIdlbl.lineBreakMode = NSLineBreakByWordWrapping;
    // EmpIdlbl.numberOfLines = 2;
    [EmpIdlbl setTextAlignment:NSTextAlignmentLeft];
    [navBar addSubview:EmpIdlbl];
    
    
    Timelbl=[[UILabel alloc] init];
    Timelbl.frame=CGRectMake(navBar.frame.size.width-62, 6,80, 40);
    [Timelbl setFont:[UIFont systemFontOfSize:13.0f]];
    [Timelbl setBackgroundColor:[UIColor clearColor]];
    [Timelbl setTextColor:[UIColor blackColor]];
    NSDate *aDate = [NSDate date];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterShortStyle];
    [formatter setTimeStyle:NSDateFormatterNoStyle];
    [formatter setDateFormat:@"HH:mm:ss"];
    NSString  *datestr;
    datestr=[formatter stringFromDate:aDate];
    Timelbl.text=datestr;
    //Timelbl.text=[NSString stringWithFormat:@"%@:%@",@"Time",datestr];
    
    // timer is set & will be triggered each second
    //[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(showTime) userInfo:nil repeats:YES];
    Timelbl.lineBreakMode = NSLineBreakByWordWrapping;
    Timelbl.numberOfLines = 2;
    [Timelbl setTextAlignment:NSTextAlignmentLeft];
    [navBar addSubview:Timelbl];
    
    
    
    p=1;
    @autoreleasepool {

    for (int i=0; i< 10; i++)
    {
        
        categorybutton = [UIButton buttonWithType:UIButtonTypeCustom];
        
        [categorybutton setFrame:CGRectMake(0,p,170,40)];
        [categorybutton addTarget:self action:@selector(categotybuttonclicked:) forControlEvents:UIControlEventTouchUpInside];
        categorybutton.tag=i;
        if (categorybutton.tag == 0)
        {
            [categorybutton setImage:[UIImage imageNamed:@"posnormal2.png"] forState:UIControlStateNormal];
        }else if (categorybutton.tag == 1)
        {
            [categorybutton setImage:[UIImage imageNamed:@"profileactive2.png"] forState:UIControlStateNormal];
        }
        else if (categorybutton.tag == 2)
        {
            [categorybutton setImage:[UIImage imageNamed:@"inventorynormal2.png"] forState:UIControlStateNormal];
        }
        else if(categorybutton.tag == 3)
        {
            [categorybutton setImage:[UIImage imageNamed:@"customernormal2.png"] forState:UIControlStateNormal];
        }
        else if (categorybutton.tag == 4)
        {
            [categorybutton setImage:[UIImage imageNamed:@"employeenormal2.png"] forState:UIControlStateNormal];
        }
        else if(categorybutton.tag == 5)
        {
            [categorybutton setImage:[UIImage imageNamed:@"settingsnormal2.png"] forState:UIControlStateNormal];
        }
        else if(categorybutton.tag == 6)
        {
            [categorybutton setImage:[UIImage imageNamed:@"reportsnormal2.png"] forState:UIControlStateNormal];
        }
        else if(categorybutton.tag == 7)
        {
            [categorybutton setImage:[UIImage imageNamed:@"contactsnormal2.png"] forState:UIControlStateNormal];
        }
        else if (categorybutton.tag == 8)
        {
            [categorybutton setImage:[UIImage imageNamed:@"storesnormal.png"] forState:UIControlStateNormal];
        }
        
        else if (categorybutton.tag == 9)
        {
            //[categorybutton setImage:[UIImage imageNamed:@"bluecolorstrip.jpg"] forState:UIControlStateNormal];
        }
        [sidemenu addSubview:categorybutton];
        p=p+categorybutton.frame.size.height;
    }
   }
    mainview=[[UIView alloc]init];
    mainview.frame=CGRectMake(20,60,width-40,height-200);
    [mainview setBackgroundColor:[UIColor grayColor]];
    [mainview  setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"hqbackground69opacity.png"]]];
    
    
    NSString *querySQL = [NSString stringWithFormat:@"SELECT userid,password FROM admin_details"];
    NSMutableArray *adminArray=[[NSMutableArray alloc]init];
    [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:adminArray];
    if ([adminArray count]==0)
    {
        
        maintoolBar = [[UIToolbar alloc] init];
        maintoolBar.frame = CGRectMake(0, 0, mainview.frame.size.width, 40);
        [maintoolBar setBackgroundImage:[UIImage imageNamed:@"toprightmenu.png"] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
        
        NSMutableArray *items=[[NSMutableArray alloc]init];
        [items addObject:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]];
        backButton = [UIButton buttonWithType:UIButtonTypeCustom];
        backButton.frame = CGRectMake(0, 0, 150, 60);
        
        // [backButton addTarget:self action:@selector(backButtonTapped1) forControlEvents:UIControlEventTouchUpInside];
        // [backButton setBackgroundImage:[UIImage imageNamed:@"topright-highlightitem-textbg.png"] forState:UIControlStateNormal];
        backButton.tag=[items indexOfObject:backButton];
        [backButton setTitle:@"Create Profile" forState:UIControlStateNormal];
        backButton.showsTouchWhenHighlighted = YES;
        
        UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
        
        
        [items  addObject:backBarButtonItem];
        [items addObject:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]];
        backButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [maintoolBar setItems:items animated:NO];
        [mainview addSubview:maintoolBar];
        
        profiledataScrollview=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 40,mainview.frame.size.width, mainview.frame.size.height-(maintoolBar.frame.size.height))];
        profiledataScrollview.scrollEnabled=YES;
        profiledataScrollview.contentSize=CGSizeMake(300,mainview.frame.size.height+100);
        [profiledataScrollview setBackgroundColor:[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f]];
        CGFloat labelwidth=(profiledataScrollview.frame.size.width/4);
        p=20;
        NSArray *labelArray;
        for (int i=0; i< 9; i++)
        {
            textLabel=[[UILabel alloc] init];
            textLabel.frame=CGRectMake(labelwidth-30, p, labelwidth+60, 40);
            
            textLabel.tag=i+100;
            [textLabel setFont:[UIFont systemFontOfSize:25.0f]];
            //[textLabel setBackgroundColor:[UIColor clearColor]];
            [textLabel setTextColor:[UIColor whiteColor]];
            if(!labelArray)
             labelArray=[[NSArray alloc] initWithObjects:@"Userid ",@"Password ",@"ConfirmPassword",@"Firstname ",@"Lastname ",@"Phonenumber ",@"Email ",@"Address ",@"",nil];
            [textLabel setText:[labelArray objectAtIndex:i]];
            [textLabel setTextAlignment:NSTextAlignmentLeft];
            [profiledataScrollview addSubview:textLabel];
            
            dataField=[[UITextField alloc] init];
            //[nameTextfield setBorderStyle:UITextBorderStyleRoundedRect];
            dataField.frame=CGRectMake(labelwidth+textLabel.frame.size.width-20, p,labelwidth, 40);
            dataField.delegate=self;
            dataField.tag=i+100;
            if (dataField.tag == 101)
            {
                dataField.secureTextEntry=YES;
            }
            if (dataField.tag == 102)
            {
                dataField.secureTextEntry=YES;
            }
            UIView *paddingview=[[UIView alloc] initWithFrame:CGRectMake(5, 0, 5, 20)];
            
            dataField.leftView = paddingview;
            dataField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
            dataField.leftViewMode = UITextFieldViewModeAlways;
            //[dataField setBackground:[UIImage imageNamed:@"addinputtextfield.png"]];
            [dataField setAutocorrectionType:UITextAutocorrectionTypeNo];
             dataField.borderStyle = UITextBorderStyleRoundedRect;
            if (dataField.tag == 108)
            {
                [dataField setBackground:[UIImage imageNamed:@" "]];
                dataField.hidden=YES;
                //dataField.borderStyle = UITextBorderStyleRoundedRect;
            }
            //[dataField addTarget:self action:@selector(adddata:) forControlEvents:UIControlEventTouchUpInside];
            
            [profiledataScrollview addSubview:dataField];
            
            p=p+60;
            
            paddingview = nil;
        }
        
        saveprofiledataBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        
        saveprofiledataBtn.frame=CGRectMake(labelwidth+40,profiledataScrollview.frame.size.height-220, 100, 30);
        [saveprofiledataBtn addTarget:self action:@selector(saveProfiledata) forControlEvents:UIControlEventTouchUpInside];
        
        //[SaveTaxButton setTitle:@"Save" forState:UIControlStateNormal];
        [saveprofiledataBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [saveprofiledataBtn setBackgroundImage:[UIImage imageNamed:@"savegreenbutton.png"] forState:UIControlStateNormal];
        [profiledataScrollview addSubview:saveprofiledataBtn];
        
        cancelProfiledata = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        
        cancelProfiledata.frame=CGRectMake(labelwidth+220, profiledataScrollview.frame.size.height-220, 100, 30);
        [cancelProfiledata addTarget:self action:@selector(Cancelprofile) forControlEvents:UIControlEventTouchUpInside];
        [cancelProfiledata setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [cancelProfiledata setBackgroundImage:[UIImage imageNamed:@"cancelgreenbutton.png"] forState:UIControlStateNormal];
        
        
        [profiledataScrollview addSubview:cancelProfiledata];
        
        [mainview addSubview:profiledataScrollview];
        [backgroundcolorview addSubview:mainview];
    }
    else
    {
        maintoolBar = [[UIToolbar alloc] init];
        maintoolBar.frame = CGRectMake(0, 0, mainview.frame.size.width, 40);
        [maintoolBar setBackgroundImage:[UIImage imageNamed:@"toprightmenu.png"] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
        CGFloat barbuttonwidth=(mainview.frame.size.width)/4;
        NSMutableArray *items=[[NSMutableArray alloc]init];
        [items addObject:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]];
        EditProfileBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        EditProfileBtn.frame = CGRectMake(0, 0, barbuttonwidth, 60);
        
        [EditProfileBtn addTarget:self action:@selector(EditProfileBarBtn) forControlEvents:UIControlEventTouchUpInside];
        // [Applicationbarbtn setBackgroundImage:[UIImage imageNamed:@"topright-highlightitem-textbg.png"] forState:UIControlStateNormal];
        EditProfileBtn.tag=[items indexOfObject:EditProfileBtn];
        [EditProfileBtn setTitle:@"Edit Profile" forState:UIControlStateNormal];
        UIImage *btnImg = [UIImage imageNamed:@"highlightedtopmenuitem.png"];
        UIImage *btnGreyImg = [btnImg stretchableImageWithLeftCapWidth:0 topCapHeight:1];
        [EditProfileBtn setBackgroundImage:btnGreyImg forState:UIControlStateNormal];
        [EditProfileBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        EditProfileBtn.showsTouchWhenHighlighted = YES;
        
        UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:EditProfileBtn];
        
        [items  addObject:backBarButtonItem];
        [items addObject:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]];
        EditPassWordBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        EditPassWordBtn.frame = CGRectMake(0, 0, barbuttonwidth, 60);
        [EditPassWordBtn setTitle:@"Edit Password" forState:UIControlStateNormal];
        [EditPassWordBtn addTarget:self action:@selector(EditPasswordBarBtn) forControlEvents:UIControlEventTouchUpInside];
        EditPassWordBtn.tag=[items indexOfObject:EditPassWordBtn];
        //[backButton2 setBackgroundImage:[UIImage imageNamed:@"topright-highlightitem-textbg.png"] forState:UIControlStateNormal];
        EditPassWordBtn.showsTouchWhenHighlighted = YES;
        
        UIBarButtonItem *backBarButtonItem2 = [[UIBarButtonItem alloc] initWithCustomView:EditPassWordBtn];
        
        [items  addObject:backBarButtonItem2];
        [items addObject:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]];
        ViewProfileBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        ViewProfileBtn.frame = CGRectMake(0, 0, barbuttonwidth-20,60);
        [ViewProfileBtn setTitle:@"View Profile" forState:UIControlStateNormal];
        
        [ViewProfileBtn addTarget:self action:@selector(ViewBarBtn) forControlEvents:UIControlEventTouchUpInside];
        //[backButton3 setBackgroundImage:[UIImage imageNamed:@"topright-highlightitem-textbg.png"] forState:UIControlStateNormal];
        ViewProfileBtn.showsTouchWhenHighlighted = YES;
        ViewProfileBtn.tag=[items indexOfObject:ViewProfileBtn];
        
        
        UIBarButtonItem *backBarButtonItem3 = [[UIBarButtonItem alloc] initWithCustomView:ViewProfileBtn];
        
        [items  addObject:backBarButtonItem3];
        [items addObject:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]];
        [maintoolBar setItems:items animated:NO];
        [mainview addSubview:maintoolBar];
        
      
        
        EditProfileBackView=[[UIView alloc]init];
        EditProfileBackView.frame=CGRectMake(10, maintoolBar.frame.size.height+10, (mainview.frame.size.width)-20, (mainview.frame.size.height)-(maintoolBar.frame.size.height+20));
        [EditProfileBackView setBackgroundColor:[UIColor whiteColor]];
        [mainview addSubview:EditProfileBackView];
        
        EditProfileView =[[UIScrollView alloc]init];
        EditProfileView.frame=CGRectMake(10, 10, EditProfileBackView.frame.size.width-20, EditProfileBackView.frame.size.height-20);
        EditProfileView.contentSize=CGSizeMake(EditProfileBackView.frame.size.width-20, EditProfileBackView.frame.size.height+200);
        
        //  EditProfileView.tintColor=[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f];
        [EditProfileView setBackgroundColor:[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f]];
        //[EditProfileView setBackgroundColor:[UIColor colorWithRed:52.0f green:170.0f/255.0f blue:220.0f/255.0f alpha:1.0f]];
        //[EditProfileView setBackgroundColor:[UIColor colorWithPatternImage:(UIImage *) ]];
        
        EditProfileView.layer.cornerRadius=8;
        [EditProfileBackView addSubview:EditProfileView];
        
        Unique_id=[[NSString alloc]init];
        Newpassword=[[NSString alloc]init];
        
        NSString *querySQL = [NSString stringWithFormat:@"SELECT userid,password,firstname,lastname,phonenumber,email, address,unique_id FROM admin_details"];
        NSMutableArray *adminArray=[[NSMutableArray alloc]init];
        [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:adminArray];
        
        NSDictionary *myDict;
        myDict=[adminArray objectAtIndex:0];
        
        userid=[myDict objectForKey:@"userid"];
        Newpassword=[myDict objectForKey:@"password"];
        //confirmpassword=[myDict objectForKey:@"password"];
        firstname=[myDict objectForKey:@"firstname"];
        lastname=[myDict objectForKey:@"lastname"];
        phonenumber=[myDict objectForKey:@"phonenumber"];
        Emailid=[myDict objectForKey:@"email"];
        address=[myDict objectForKey:@"address"];
        Unique_id=[myDict objectForKey:@"unique_id"];
        
        
        //NSArray *labelArray=[[NSArray alloc] initWithObjects:@"Userid ",@"Firstname ",@"Lastname ",@"Phonenumber ",@"Email ",@"Address ",@"",nil];
        CGFloat Profilewidth=(EditProfileView.frame.size.width/4);
        
        useridlbl=[[UILabel alloc] init];
        useridlbl.frame=CGRectMake(Profilewidth-50, 20, Profilewidth+20, 40);
        [useridlbl setFont:[UIFont systemFontOfSize:25.0f]];
        [useridlbl setBackgroundColor:[UIColor clearColor]];
        [useridlbl setTextColor:[UIColor whiteColor]];
        [useridlbl setText:@"Userid"];
        [useridlbl setTextAlignment:NSTextAlignmentLeft];
        [EditProfileView addSubview:useridlbl];
        
        useridField=[[UITextField alloc] init];
        //[nameTextfield setBorderStyle:UITextBorderStyleRoundedRect];
        useridField.frame=CGRectMake(Profilewidth+useridlbl.frame.size.width-40, 20,Profilewidth+100, 40);
        useridField.delegate=self;
        UIView *paddingview=[[UIView alloc] initWithFrame:CGRectMake(5, 0, 5, 20)];
        
        useridField.leftView = paddingview;
        useridField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
        useridField.leftViewMode = UITextFieldViewModeAlways;
        [useridField setBackground:[UIImage imageNamed:@"addinputtextfield.png"]];
        [useridField setAutocorrectionType:UITextAutocorrectionTypeNo];
        useridField.delegate=self;
        useridField.text=userid;
        // [useridField addTarget:self action:@selector(gettextFromTextField:) forControlEvents:UIControlEventEditingDidEnd];
        [EditProfileView addSubview:useridField];
        
        Firstnamelbl=[[UILabel alloc] init];
        Firstnamelbl.frame=CGRectMake(Profilewidth-50,80, Profilewidth+20, 40);
        [Firstnamelbl setFont:[UIFont systemFontOfSize:25.0f]];
        [Firstnamelbl setBackgroundColor:[UIColor clearColor]];
        [Firstnamelbl setTextColor:[UIColor whiteColor]];
        [Firstnamelbl setText:@"Firstname"];
        [Firstnamelbl setTextAlignment:NSTextAlignmentLeft];
        [EditProfileView addSubview:Firstnamelbl];
        
        FirstnameField=[[UITextField alloc] init];
        //[nameTextfield setBorderStyle:UITextBorderStyleRoundedRect];
        FirstnameField.frame=CGRectMake(Profilewidth+useridlbl.frame.size.width-40, 80,Profilewidth+100, 40);
        FirstnameField.delegate=self;
        UIView *paddingview2=[[UIView alloc] initWithFrame:CGRectMake(5, 0, 5, 20)];
        FirstnameField.leftView = paddingview2;
        FirstnameField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
        FirstnameField.leftViewMode = UITextFieldViewModeAlways;
        [FirstnameField setBackground:[UIImage imageNamed:@"addinputtextfield.png"]];
        [FirstnameField setAutocorrectionType:UITextAutocorrectionTypeNo];
        FirstnameField.text=firstname;
        FirstnameField.delegate=self;
        [EditProfileView addSubview:FirstnameField];
        
        lastnamelbl=[[UILabel alloc] init];
        lastnamelbl.frame=CGRectMake(Profilewidth-50,140, Profilewidth+20, 40);
        [lastnamelbl setFont:[UIFont systemFontOfSize:25.0f]];
        [lastnamelbl setBackgroundColor:[UIColor clearColor]];
        [lastnamelbl setTextColor:[UIColor whiteColor]];
        [lastnamelbl setText:@"Lastname"];
        [lastnamelbl setTextAlignment:NSTextAlignmentLeft];
        [EditProfileView addSubview:lastnamelbl];
        
        lastnameField=[[UITextField alloc] init];
        //[nameTextfield setBorderStyle:UITextBorderStyleRoundedRect];
        lastnameField.frame=CGRectMake(Profilewidth+useridlbl.frame.size.width-40,140,Profilewidth+100, 40);
        lastnameField.delegate=self;
        UIView *paddingview3=[[UIView alloc] initWithFrame:CGRectMake(5, 0, 5, 20)];
        lastnameField.leftView = paddingview3;
        lastnameField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
        lastnameField.leftViewMode = UITextFieldViewModeAlways;
        [lastnameField setBackground:[UIImage imageNamed:@"addinputtextfield.png"]];
        [lastnameField setAutocorrectionType:UITextAutocorrectionTypeNo];
        lastnameField.delegate=self;
        lastnameField.text=lastname;
        [EditProfileView addSubview:lastnameField];
        
        phnumberlbl=[[UILabel alloc] init];
        phnumberlbl.frame=CGRectMake(Profilewidth-50,200, Profilewidth+20, 40);
        [phnumberlbl setFont:[UIFont systemFontOfSize:25.0f]];
        [phnumberlbl setBackgroundColor:[UIColor clearColor]];
        [phnumberlbl setTextColor:[UIColor whiteColor]];
        [phnumberlbl setText:@"Phonenumber"];
        [phnumberlbl setTextAlignment:NSTextAlignmentLeft];
        [EditProfileView addSubview:phnumberlbl];
        
        PhnumberField=[[UITextField alloc] init];
        //[nameTextfield setBorderStyle:UITextBorderStyleRoundedRect];
        PhnumberField.frame=CGRectMake(Profilewidth+useridlbl.frame.size.width-40, 200,Profilewidth+100, 40);
        PhnumberField.delegate=self;
        UIView *paddingview4=[[UIView alloc] initWithFrame:CGRectMake(5, 0, 5, 20)];
        PhnumberField.leftView = paddingview4;
        PhnumberField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
        PhnumberField.leftViewMode = UITextFieldViewModeAlways;
        [PhnumberField setBackground:[UIImage imageNamed:@"addinputtextfield.png"]];
        [PhnumberField setAutocorrectionType:UITextAutocorrectionTypeNo];
        PhnumberField.delegate=self;
        PhnumberField.text=phonenumber;
        [EditProfileView addSubview:PhnumberField];
        
        emaillbl=[[UILabel alloc] init];
        emaillbl.frame=CGRectMake(Profilewidth-50,260, Profilewidth+20, 40);
        [emaillbl setFont:[UIFont systemFontOfSize:25.0f]];
        [emaillbl setBackgroundColor:[UIColor clearColor]];
        [emaillbl setTextColor:[UIColor whiteColor]];
        [emaillbl setText:@"Email"];
        [emaillbl setTextAlignment:NSTextAlignmentLeft];
        [EditProfileView addSubview:emaillbl];
        
        EmailField=[[UITextField alloc] init];
        //[nameTextfield setBorderStyle:UITextBorderStyleRoundedRect];
        EmailField.frame=CGRectMake(Profilewidth+useridlbl.frame.size.width-40, 260,Profilewidth+100, 40);
        EmailField.delegate=self;
        UIView *paddingview5=[[UIView alloc] initWithFrame:CGRectMake(5, 0, 5, 20)];
        EmailField.leftView = paddingview5;
        EmailField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
        EmailField.leftViewMode = UITextFieldViewModeAlways;
        [EmailField setBackground:[UIImage imageNamed:@"addinputtextfield.png"]];
        [EmailField setAutocorrectionType:UITextAutocorrectionTypeNo];
        EmailField.delegate=self;
        EmailField.text=Emailid;
        [EditProfileView addSubview:EmailField];
        
        addresslbl=[[UILabel alloc] init];
        addresslbl.frame=CGRectMake(Profilewidth-50,320, Profilewidth+20, 40);
        [addresslbl setFont:[UIFont systemFontOfSize:25.0f]];
        [addresslbl setBackgroundColor:[UIColor clearColor]];
        [addresslbl setTextColor:[UIColor whiteColor]];
        [addresslbl setText:@"Address"];
        [addresslbl setTextAlignment:NSTextAlignmentLeft];
        [EditProfileView addSubview:addresslbl];
        
        addressField=[[UITextField alloc] init];
        //[nameTextfield setBorderStyle:UITextBorderStyleRoundedRect];
        addressField.frame=CGRectMake(Profilewidth+useridlbl.frame.size.width-40, 320,Profilewidth+100, 40);
        addressField.delegate=self;
        UIView *paddingview6=[[UIView alloc] initWithFrame:CGRectMake(5, 0, 5, 20)];
        addressField.leftView = paddingview6;
        addressField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
        addressField.leftViewMode = UITextFieldViewModeAlways;
        [addressField setBackground:[UIImage imageNamed:@"addinputtextfield.png"]];
        [addressField setAutocorrectionType:UITextAutocorrectionTypeNo];
        addressField.delegate=self;
        addressField.text=address;
        [EditProfileView addSubview:addressField];
        
        
        
        SaveEditprofileBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        
        SaveEditprofileBtn.frame=CGRectMake(Profilewidth+Profilewidth/2+60,400, 100, 30);
        [SaveEditprofileBtn addTarget:self action:@selector(saveEditProfiledata) forControlEvents:UIControlEventTouchUpInside];
        
        //[SaveTaxButton setTitle:@"Save" forState:UIControlStateNormal];
        [SaveEditprofileBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [SaveEditprofileBtn setBackgroundImage:[UIImage imageNamed:@"savegreenbutton.png"] forState:UIControlStateNormal];
        [EditProfileView addSubview:SaveEditprofileBtn];
        [backgroundcolorview addSubview:mainview];
        
        
        [useridField setReturnKeyType:UIReturnKeyNext];
        [FirstnameField setReturnKeyType:UIReturnKeyNext];
        [lastnameField setReturnKeyType:UIReturnKeyNext];
        [EmailField setReturnKeyType:UIReturnKeyNext];
        [PhnumberField setReturnKeyType:UIReturnKeyNext];
        
        [addressField setReturnKeyType:UIReturnKeyDone];
    }
    
    logoimageview=[[UIImageView alloc]init];
    logoimageview.frame=CGRectMake(50, (backgroundcolorview.frame.size.height)+5+y,(height-(backgroundcolorview.frame.size.height)-30), (height-(backgroundcolorview.frame.size.height)-30));
    [logoimageview setImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"aoneposlogo" ofType:@"png"]]];
    [self.view addSubview:logoimageview];
    
    helpiconButton = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [helpiconButton setFrame:CGRectMake(width-180,y+40,70,70)];
    [helpiconButton addTarget:self action:@selector(helpiconclicked) forControlEvents:UIControlEventTouchUpInside];
    
    //[helpiconButton setImage:[UIImage imageNamed:@"helpicon.png"] forState:UIControlStateNormal];
    [helpiconButton setImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"helpicon" ofType:@"png"]] forState:UIControlStateNormal];
    
    [self.view addSubview:helpiconButton];
    logouticonButton = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [logouticonButton setFrame:CGRectMake(width-100,y+40,70,70)];
    [logouticonButton addTarget:self action:@selector(logoutButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    
    //[logouticonButton setImage:[UIImage imageNamed:@"logoutbutton.png"] forState:UIControlStateNormal];
    [logouticonButton setImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"logoutbutton" ofType:@"png"]] forState:UIControlStateNormal];
    [self.view addSubview:logouticonButton];
    
    Emailid=[[NSString alloc]init];
    password=[[NSString alloc]init];
    userid=[[NSString alloc]init];
    confirmpassword=[[NSString alloc]init];
    firstname=[[NSString alloc]init];
    middlename=[[NSString alloc]init];
    lastname=[[NSString alloc]init];
    phonenumber=[[NSString alloc]init];
    address=[[NSString alloc]init];
    
  
    
    y=0;
    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
    {
        y=y+20;
        
        
    }
    
    isLandScope = UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation);
    
    [self updateUI];
    
     helpiconButton.hidden=YES;
    // Do any additional setup after loading the view from its nib.
}
-(void)viewWillAppear:(BOOL)animated
{
      [super  viewWillAppear:animated];
    isLandScope = UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation);
    [self updateUI];
}
-(void)showTime
{
    
    NSDate *aDate = [NSDate date];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterShortStyle];
    [formatter setTimeStyle:NSDateFormatterNoStyle];
    [formatter setDateFormat:@"HH:mm:ss"];
    NSString *datestr;
    datestr=[formatter stringFromDate:aDate];
    Timelbl.text=datestr;
    // Timelbl.text=[NSString stringWithFormat:@"%@:%@",@"Time",datestr];
    //Timelbl.text=[[NSDate date] description];
    
    
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if (textField == useridField) {
		[textField resignFirstResponder];
		[FirstnameField becomeFirstResponder];
	}
	else if (textField == FirstnameField) {
		[textField resignFirstResponder];
        [lastnameField becomeFirstResponder];
    }
    else if (textField == FirstnameField) {
		[textField resignFirstResponder];
        [lastnameField becomeFirstResponder];
    }
    else if (textField == lastnameField) {
		[textField resignFirstResponder];
        [PhnumberField becomeFirstResponder];
    }
    else if (textField == PhnumberField) {
		[textField resignFirstResponder];
        [EmailField becomeFirstResponder];
    }
    else if (textField == EmailField) {
		[textField resignFirstResponder];
        [addressField becomeFirstResponder];
    }
    else if (textField == addressField) {
		[textField resignFirstResponder];
    }
    [textField resignFirstResponder];
    return YES;
}
-(void)EditProfileBarBtn
{
    [ViewProfileBtn setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [ViewProfileBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [EditPassWordBtn setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [EditPassWordBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    UIImage *btnImg = [UIImage imageNamed:@"highlightedtopmenuitem.png"];
    UIImage *btnGreyImg = [btnImg stretchableImageWithLeftCapWidth:0 topCapHeight:1];
    [EditProfileBtn setBackgroundImage:btnGreyImg forState:UIControlStateNormal];
    [EditProfileBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    [EditPasswordBackView removeFromSuperview];
    [ViewProfiledatabackView removeFromSuperview];
    [mainview addSubview:EditProfileBackView];
    
   
    
}
-(void)saveEditProfiledata
{
    
   
   
    NSString *insertSQL = [NSString stringWithFormat: @"UPDATE  admin_details SET firstname=?,lastname=?,phonenumber=?,email=?,address=? WHERE userid=?"];
    
    NSMutableArray *updatedminArray=[[NSMutableArray alloc]initWithObjects:FirstnameField.text,lastnameField.text,PhnumberField.text,EmailField.text,addressField.text,useridField.text, nil];

    
    [[DataBaseManager dataBaseManager]executeRecordsWithQuery:insertSQL withArguments:updatedminArray];
    
    JsonSendDataDict=[[NSMutableDictionary alloc] init];
    
    NSDictionary *myDict=[[NSDictionary alloc]initWithObjectsAndKeys:useridField.text,@"userid",FirstnameField.text,@"firstname",lastnameField.text,@"lastname",PhnumberField.text,@"phonenumber",EmailField.text,@"email",addressField.text,@"address",Unique_id,@"unique_id",Newpassword,@"password",Newpassword,@"server_password", nil];
    
    //NSLog(@"data dict %@",myDict);
    NSMutableArray *jsonArray=[NSMutableArray arrayWithObjects:myDict, nil];
    [JsonSendDataDict setObject:jsonArray forKey:@"fields"];
    NSDictionary *jsonDict = [NSDictionary dictionaryWithDictionary:JsonSendDataDict];
    
    
    NSError *err2;
    
    NSData *jsonData2 = [NSJSONSerialization dataWithJSONObject:jsonDict options:kNilOptions error:&err2];
    
    NSString *str2=[[NSString alloc] initWithData:jsonData2 encoding:NSUTF8StringEncoding];
    if(![generalDataObject  connectedToInternet]){
        
       
        NSString *insertSQL =@"insert into pending_queries (query_type,user_id,page_url,parameters,table_name,current_time) values(?,?,?,?,?,?)";
        
        NSMutableArray *pendingArray=[[NSMutableArray alloc]initWithObjects:@"UPDATE",[generalDataObject  userID],@"saveinfo.php?",str2,@"admin_details",[generalDataObject getsystemDatetime], nil];
        
        [[DataBaseManager dataBaseManager] executeRecordsWithQuery:insertSQL withArguments:pendingArray];
        
        
    }
    
    else if([generalDataObject  connectedToInternet]){
        
        
        if ([[generalDataObject  OriginalbaseURLstr] length]>0)
        {
            //NSLog(@"%@",str2);
            NSString *string=[NSString stringWithFormat:@"%@saveinfo.php?tablename=admin_details&systemtime=%@&userid=%@&sessionid=%@&data=%@&update=true",[generalDataObject  OriginalbaseURLstr],[[generalDataObject getsystemDatetime] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],useridField.text,[generalDataObject  genRandStringLength:20],[str2 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
            
            //NSLog(@"%@",str2);
            
            NSURL *url=[NSURL URLWithString:string];
            NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
            //NSLog(@"%@",url);
            
            [request setHTTPMethod:@"POST"];
            [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
            //[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
            
            
            
            connection1 = [NSURLConnection connectionWithRequest:request delegate:self];
            
            [connection1 start];
        }
    }
    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Success" message:@"Profile data changed successfully" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
    
    [alert show];
    
  //useridField.text=@"";FirstnameField.text=@"";lastnameField.text=@"";PhnumberField.text=@"";EmailField.text=@"";addressField.text=@"";
}
-(void)EditPasswordBarBtn
{
    [ViewProfileBtn setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [ViewProfileBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [EditProfileBtn setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [EditProfileBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    UIImage *btnImg = [UIImage imageNamed:@"highlightedtopmenuitem.png"];
    UIImage *btnGreyImg = [btnImg stretchableImageWithLeftCapWidth:0 topCapHeight:1];
    [EditPassWordBtn setBackgroundImage:btnGreyImg forState:UIControlStateNormal];
    [EditPassWordBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [ViewProfiledatabackView removeFromSuperview];
    [EditProfileBackView removeFromSuperview];
    
    EditPasswordBackView=[[UIView alloc]init];
    EditPasswordBackView.frame=CGRectMake(10, maintoolBar.frame.size.height+10, (mainview.frame.size.width)-20, (mainview.frame.size.height)-(maintoolBar.frame.size.height+20));
    [EditPasswordBackView setBackgroundColor:[UIColor whiteColor]];
    [mainview addSubview:EditPasswordBackView];
    
    EditPasswordView =[[UIScrollView alloc]init];
    EditPasswordView.frame=CGRectMake(10, 10, EditPasswordBackView.frame.size.width-20, EditPasswordBackView.frame.size.height-20);
    EditPasswordView.contentSize=CGSizeMake( EditPasswordBackView.frame.size.width-20, EditPasswordBackView.frame.size.height+100);
    [EditPasswordView setBackgroundColor:[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f]];
   
    NSString *querySQL = [NSString stringWithFormat:@"SELECT userid,password FROM admin_details"];
    NSMutableArray *adminArray=[[NSMutableArray alloc]init];
    [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:adminArray];
    for (NSDictionary *myDict in adminArray)
    {
        userid=[myDict objectForKey:@"userid"];
        password=[myDict objectForKey:@"password"];
    }
    EditPasswordView.layer.cornerRadius=8;
    [EditPasswordBackView addSubview:EditPasswordView];
    
    CGFloat editw=EditPasswordView.frame.size.width/4;
  
    
    newpwdlbl=[[UILabel alloc] init];
    newpwdlbl.frame=CGRectMake(editw-30,80, editw, 40);
    [newpwdlbl setFont:[UIFont systemFontOfSize:25.0f]];
    [newpwdlbl setBackgroundColor:[UIColor clearColor]];
    [newpwdlbl setTextColor:[UIColor whiteColor]];
    [newpwdlbl setText:@"New Password"];
    [newpwdlbl setTextAlignment:NSTextAlignmentLeft];
    [EditPasswordView addSubview:newpwdlbl];
    
    NewpwdField=[[UITextField alloc] init];
    //[nameTextfield setBorderStyle:UITextBorderStyleRoundedRect];
    NewpwdField.frame=CGRectMake(editw+newpwdlbl.frame.size.width-20, 80,editw+60, 40);
    NewpwdField.delegate=self;
    UIView *paddingview2=[[UIView alloc] initWithFrame:CGRectMake(5, 0, 5, 20)];
    NewpwdField.leftView = paddingview2;
     NewpwdField.secureTextEntry=YES;
    NewpwdField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
    NewpwdField.leftViewMode = UITextFieldViewModeAlways;
    [NewpwdField setBackground:[UIImage imageNamed:@"addinputtextfield.png"]];
    [NewpwdField setAutocorrectionType:UITextAutocorrectionTypeNo];
    [EditPasswordView addSubview:NewpwdField];
    
    ConfirmPasswordlbl=[[UILabel alloc] init];
    ConfirmPasswordlbl.frame=CGRectMake(editw-70,140, editw+50, 40);
    [ConfirmPasswordlbl setFont:[UIFont systemFontOfSize:25.0f]];
    [ConfirmPasswordlbl setBackgroundColor:[UIColor clearColor]];
    [ConfirmPasswordlbl setTextColor:[UIColor whiteColor]];
    
    [ConfirmPasswordlbl setText:@"Confirm Password"];
    [ConfirmPasswordlbl setTextAlignment:NSTextAlignmentLeft];
    [EditPasswordView addSubview:ConfirmPasswordlbl];
    
    ConfirmPwdField=[[UITextField alloc] init];
    //[nameTextfield setBorderStyle:UITextBorderStyleRoundedRect];
    ConfirmPwdField.frame=CGRectMake(editw+newpwdlbl.frame.size.width-20, 140,editw+60, 40);
    ConfirmPwdField.delegate=self;
    
    UIView *paddingview3=[[UIView alloc] initWithFrame:CGRectMake(5, 0, 5, 20)];
    ConfirmPwdField.secureTextEntry=YES;
    ConfirmPwdField.leftView = paddingview3;
    ConfirmPwdField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
    ConfirmPwdField.leftViewMode = UITextFieldViewModeAlways;
    [ConfirmPwdField setBackground:[UIImage imageNamed:@"addinputtextfield.png"]];
    [ConfirmPwdField setAutocorrectionType:UITextAutocorrectionTypeNo];
     [EditPasswordView addSubview:ConfirmPwdField];
    
    SaveEditPwdBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    
    SaveEditPwdBtn.frame=CGRectMake(editw+editw/2, 240, 80, 30);
    [SaveEditPwdBtn addTarget:self action:@selector(SaveEditPasswordClicked) forControlEvents:UIControlEventTouchUpInside];
    
    //[SaveTaxButton setTitle:@"Save" forState:UIControlStateNormal];
    [SaveEditPwdBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [SaveEditPwdBtn setBackgroundImage:[UIImage imageNamed:@"savegreenbutton.png"] forState:UIControlStateNormal];
    [EditPasswordView addSubview:SaveEditPwdBtn];
    
    CancelEditpwdBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    
    CancelEditpwdBtn.frame=CGRectMake(editw+100+editw/2, 240, 80, 30);
    [CancelEditpwdBtn addTarget:self action:@selector(CancelEditPasswordClicked) forControlEvents:UIControlEventTouchUpInside];
    [CancelEditpwdBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [CancelEditpwdBtn setBackgroundImage:[UIImage imageNamed:@"cancelgreenbutton.png"] forState:UIControlStateNormal];
    // [CancelTaxButton setTitle:@"Cancel" forState:UIControlStateNormal];
    
    [EditPasswordView addSubview:CancelEditpwdBtn];
    
}
-(void)ViewBarBtn
{
    [EditPassWordBtn setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [EditPassWordBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [EditProfileBtn setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [EditProfileBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    UIImage *btnImg = [UIImage imageNamed:@"highlightedtopmenuitem.png"];
    UIImage *btnGreyImg = [btnImg stretchableImageWithLeftCapWidth:0 topCapHeight:1];
    [ViewProfileBtn setBackgroundImage:btnGreyImg forState:UIControlStateNormal];
    [ViewProfileBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [EditPasswordBackView removeFromSuperview];
    [EditProfileBackView removeFromSuperview];
    
      NSString *querySQL = [NSString stringWithFormat:@"SELECT userid as User_ID,firstname as First_Name,lastname as Last_Name,phonenumber as Phone,email as Email_Address,address as Address FROM admin_details"];
    NSMutableArray *adminsArra=[[NSMutableArray alloc]init];
    [[DataBaseManager dataBaseManager]execute:querySQL resultsArray:adminsArra];
    if ([adminsArra count]>0)
    {
        NSMutableDictionary *dict;
        dict=[adminsArra objectAtIndex:0];
       
        
       
        allkeysArray=[[NSArray alloc]init];
        AllvaluesArray=[[NSArray alloc]init];
        
        allkeysArray=[dict allKeys];

        
        AllvaluesArray=[dict allValues];
    }
  
    
    
//View profile data
    
    ViewProfiledatabackView=[[UIView alloc]init];
    ViewProfiledatabackView.frame=CGRectMake(10, maintoolBar.frame.size.height+10, (mainview.frame.size.width)-20, (mainview.frame.size.height)-(maintoolBar.frame.size.height+20));
    [ViewProfiledatabackView setBackgroundColor:[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f]];
    [mainview addSubview:ViewProfiledatabackView];
    
   
    ProfileDataTable =[[UITableView alloc]init];
    if (isLandScope)
    {
          ProfileDataTable.frame=CGRectMake(10, 10, ViewProfiledatabackView.frame.size.width-20, ViewProfiledatabackView.frame.size.height-20);
    }
    else
    {
          ProfileDataTable.frame=CGRectMake(10, 50, ViewProfiledatabackView.frame.size.width-20, ViewProfiledatabackView.frame.size.height-200);
    }
  
    ProfileDataTable.delegate=self;
    ProfileDataTable.dataSource=self;
    [ProfileDataTable setBackgroundColor:[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f]];
    
    ProfileDataTable.layer.cornerRadius=8;
    [ViewProfiledatabackView addSubview:ProfileDataTable];
  
    
}

-(void)SaveEditPasswordClicked
{
    NSString *EditConfirmpwd;
    NSString *Editpassword;
    Editpassword=NewpwdField.text;
    EditConfirmpwd=ConfirmPwdField.text;
    Editpassword=[Editpassword encodeString:Editpassword] ;
    EditConfirmpwd=[EditConfirmpwd encodeString:EditConfirmpwd];
    if ([EditConfirmpwd isEqualToString:Editpassword])
    {
        if(![generalDataObject  connectedToInternet])
        {
            NSString *insertSQL =@"insert into pending_queries (query_type,user_id,page_url,parameters,table_name,current_time) values(?,?,?,?,?,?)";
            NSMutableArray *pendingArray=[[NSMutableArray alloc]initWithObjects:@"modifypassword",[generalDataObject  userID],[NSString stringWithFormat:@"userid=%@&edituserid=%@&sessionid=%@&newpassword=%@&Currentsystemtime=%@",[generalDataObject  userID],[generalDataObject  userID],[generalDataObject  deviceID],Editpassword,[[generalDataObject getsystemDatetime] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]],@"",[generalDataObject getsystemDatetime], nil];
            
            [[DataBaseManager dataBaseManager]executeRecordsWithQuery:insertSQL withArguments:pendingArray];

            
        }
        else if([generalDataObject  connectedToInternet])
        {
            
            if ([[generalDataObject  OriginalbaseURLstr] length]>0)
            {
                
                
                NSString *geturlstring=[NSString stringWithFormat:@"%@change-password.php?userid=%@&edituserid=%@&sessionid=%@&newpassword=%@&Currentsystemtime=%@",[generalDataObject  OriginalbaseURLstr],[generalDataObject  userID],[generalDataObject  userID],[generalDataObject  deviceID],Editpassword,[[generalDataObject getsystemDatetime] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
                ////NSLog(@"%@",geturlstring);
                NSURL *url = [NSURL URLWithString:geturlstring];
                //NSLog(@"%@",url);
                NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
                
                
                [request setHTTPMethod:@"POST"];
                [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
                //[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
                
                
                EditConnection=[NSURLConnection connectionWithRequest:request  delegate:self];
                
            }
        }
        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Success" message:@"Password changed successfully" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
        
        [alert show];
        OldpwdField.text=@"";
        NewpwdField.text=@"";
        ConfirmPwdField.text=@"";
    }
    else
    {
        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"message" message:@"new password and confirm password not equal" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
        
        [alert show];
    }
   
    
  
}
-(void)CancelEditPasswordClicked
{
    NewpwdField.text=@"";
    ConfirmPwdField.text=@"";
}
- (BOOL)shouldAutorotate
{
   
    return YES;
    
    
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    if(textField == useridField)
    {
        [textField resignFirstResponder];
        // Show you custom picker here....
        return NO;
    }
    return YES;
}

-(void)textFieldDidEndEditing:(UITextField *)textField
{
    //Use this method insted of addTarget:
    
    if (textField.tag == 100)
    {
        
       userid=textField.text;
    }
    if (textField.tag == 101)
    {
       password=textField.text;
    }
    if (textField.tag == 102)
    {
        confirmpassword=textField.text;
    }
    if (textField.tag == 103)
    {
        
        firstname=textField.text;
    }
   
    if (textField.tag == 104)
    {
        lastname=textField.text;
    }
    if (textField.tag == 105)
    {
        
        phonenumber=textField.text;
    }
    if (textField.tag == 106)
    {
        Emailid=textField.text;
    }
    if (textField.tag ==107)
    {
        address=textField.text;
    }
    
}
-(BOOL) NSStringIsValidEmail:(NSString *)checkString
{
    BOOL stricterFilter = YES; // Discussion http://blog.logichigh.com/2010/09/02/validating-an-e-mail-address/
    NSString *stricterFilterString = @"[A-Z0-9a-z\\._%+-]+@([A-Za-z0-9-]+\\.)+[A-Za-z]{2,25}";
    NSString *laxString = @".+@([A-Za-z0-9]+\\.)+[A-Za-z]{2}[A-Za-z]*";
    NSString *emailRegex = stricterFilter ? stricterFilterString : laxString;
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
    return [emailTest evaluateWithObject:checkString];
}
-(BOOL) NSStringisvalidpassword:(NSString *)checkpassword
{
    
    NSString *passwordRegex =@"^.*(?=.{8,})(?=.*d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$";
    NSPredicate *passwordTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", passwordRegex];
    
    return  [passwordTest evaluateWithObject:checkpassword];
}
-(void)saveProfiledata
{
    NSString *myunique_id=[generalDataObject  genRandStringLength:15];
    NSString *date=[generalDataObject getsystemDatetime];
    password=[[NSString alloc]init];
    password=[password encodeString:password];
    
  if ([self NSStringIsValidEmail:Emailid]){
            //NSLog(@" valid email id");
      
        
      
       NSString *insertSQL =@"insert into admin_details (userid,password,firstname,lastname,phonenumber,email,address,unique_id,created_timestamp,modified_timestamp) values(?,?,?,?,?,?,?,?,?,?)";
      NSMutableArray *adminArray=[[NSMutableArray alloc]initWithObjects:userid,password,firstname,lastname,phonenumber,Emailid,address,myunique_id,date,date, nil];
      [[DataBaseManager dataBaseManager]executeRecordsWithQuery:insertSQL withArguments:adminArray];
    
                    JsonSendDataDict=[[NSMutableDictionary alloc] init];
                NSDictionary *myDict=[[NSDictionary alloc]initWithObjectsAndKeys:userid,@"userid",password,@"password",firstname,@"firstname",lastname,@"lastname",phonenumber,@"phonenumber",Emailid,@"email",address,@"address",myunique_id,@"unique_id",date,@"created_timestamp",date,@"modified_timestamp", nil];
                
                NSMutableArray *jsonArray=[NSMutableArray arrayWithObjects:myDict, nil];
                [JsonSendDataDict setObject:jsonArray forKey:@"fields"];
                NSDictionary *jsonDict = [NSDictionary dictionaryWithDictionary:JsonSendDataDict];
                
                
                NSError *err;
                
                NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDict options:kNilOptions error:&err];
                
                NSString *str=[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
                if(![generalDataObject  connectedToInternet])
                {
                    
                    NSString *insertSQL =@"insert into pending_queries (query_type,user_id,page_url,parameters,table_name,current_time) values(?,?,?,?,?,?)";
                    NSMutableArray *pendingArray=[[NSMutableArray alloc]initWithObjects:@"createadminprofile",[generalDataObject  userID],str,@"admin_details",[generalDataObject getsystemDatetime], nil];
                    
                    [[DataBaseManager dataBaseManager]executeRecordsWithQuery:insertSQL withArguments:pendingArray];
                    
                    
                }
                else if([generalDataObject  connectedToInternet])
                {
                    if ([[generalDataObject  OriginalbaseURLstr] length]>0)
                    {
                    password=[password encodeString:password];
                    confirmpassword=[confirmpassword encodeString:confirmpassword];
                
                    //NSLog(@"%@",str);
                    NSString *string=[NSString stringWithFormat:@"%@create-admin-profile.php?defaultusername=01&defaultpassword=admin&data=%@",[generalDataObject  OriginalbaseURLstr],[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
                    //NSLog(@"%@",string);
                    
                    
                    NSURL *url=[NSURL URLWithString:string];
                    //NSLog(@"%@",url);
                    
                    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
                    CategoryConnection = [NSURLConnection connectionWithRequest:request delegate:self];
                    
                    [CategoryConnection start];
                    }
                }
    
      saveProfileAlert=[[UIAlertView alloc] initWithTitle:@"Success" message:@"ProfileData Saved" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
      [saveProfileAlert show];
    }else{
           
            UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"message" message:@"not valid email id" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
            [alert show];
        }
    
    
    password=nil;
   
    
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
{
    if (alertView==saveProfileAlert && buttonIndex==0){
        NSArray *viewS = [self.navigationController viewControllers];
        [self.navigationController popToViewController:[viewS objectAtIndex:1] animated:YES];
        [self releaseViews];
        
    }
}
- (void)edituserid:(UITextField *)textField
{
    NSInteger selected=textField.tag;
    if(selected == 100)
    {
        [textField resignFirstResponder];
        // Show you custom picker here....
       // return NO;
    }
    //return YES;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    return 40;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    // This will create a "invisible" footer
    return 0.01f;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return [UIView new];
    
    // If you are not using ARC:
    // return [[UIView new] autorelease];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if(!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil];
    }
    
    if (tableView== ProfileDataTable)
    {
    
        UILabel  *nametext=[[UILabel alloc] initWithFrame:CGRectMake(25, 0, 250, 40)];
        
        [nametext setBackgroundColor:[UIColor clearColor]];
        [nametext setTextColor:[UIColor whiteColor]];
        //nametext.editable=NO;
        //[nametext setTextAlignment:NSTextAlignmentNatural];
        NSString *fieldName=[allkeysArray objectAtIndex:indexPath.row];
        fieldName=[fieldName stringByReplacingOccurrencesOfString:@"_" withString:@" "];
        
        [nametext setFont:[UIFont systemFontOfSize:25.0f]];
        [nametext setText:fieldName];
        [cell.contentView addSubview:nametext];
        UILabel  *cityText=[[UILabel alloc] initWithFrame:CGRectMake(ProfileDataTable.frame.size.width/2-40, 0, 420, 40)];
        [cityText setBackgroundColor:[UIColor clearColor]];
        [cityText setTextColor:[UIColor whiteColor]];
        [cityText setFont:[UIFont systemFontOfSize:22.0f]];
        //cityText.editable=NO;
        //[cityText setTextAlignment:NSTextAlignmentNatural];
        [cityText setText:[AllvaluesArray objectAtIndex:indexPath.row]];
        [cell.contentView addSubview:cityText];
        fieldName=nil;
        if (indexPath.row%2==0)
        {
            
            cell.contentView.backgroundColor=[UIColor colorWithRed:64.0f/255.0f green:96.0f/255.0f blue:120.0f/255.0f alpha:1.0f];
        }
        else
            
        {
            cell.contentView.backgroundColor=[UIColor colorWithRed:56.0f/255.0f green:104.0f/255.0f blue:128.0f/255.0f alpha:1.0f];
            
        }
        
    }
    return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView== ProfileDataTable)
    {
        return [allkeysArray count];
        
    }
    return YES;
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    
    if (connection == connection1){
        responseData = [[NSMutableData alloc] init];
    }else if (connection == CategoryConnection){
        CatresponseData = [[NSMutableData alloc] init];
       
    }else if (connection == EditConnection){
        EditResponseData = [[NSMutableData alloc] init];
        
    }
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    
    if (connection == connection1){
        [responseData appendData:data];
    }else if (connection == CategoryConnection){
        [CatresponseData appendData:data];
    }else if (connection == EditConnection){
        [EditResponseData appendData:data];
    }
    
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    if (connection == connection1){
        
        NSString *responseStr = [[NSString alloc] initWithBytes:[responseData mutableBytes] length:[responseData length] encoding:NSUTF8StringEncoding];
        
        NSError *error;
        dataDict=[[NSMutableDictionary alloc] init];
        NSData *jsonData = [responseStr dataUsingEncoding:NSUTF8StringEncoding];
        dataDict =[NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
        //NSLog(@"%@",dataDict);
        NSMutableArray *deleteArray=[dataDict objectForKey:@"delete-queries"];
        NSMutableArray *insertsArray=[dataDict objectForKey:@"insert-queries"];
        NSMutableArray *deletesArray;
        for (int i=0; i<[deleteArray count]; i++)
        {
            NSString *foo=[deleteArray objectAtIndex:i];
            NSString* bar = [foo stringByReplacingOccurrencesOfString:@"'" withString:@"\""];
            NSString* deletestr = [bar stringByReplacingOccurrencesOfString:@"\\\"" withString:@"'"];
           [[DataBaseManager dataBaseManager]executeRecordsWithQuery:deletestr withArguments:deletesArray];
            
            NSString *foo2=[insertsArray objectAtIndex:i];
            NSString* bar2 = [foo2 stringByReplacingOccurrencesOfString:@"'" withString:@"\""];
            NSString* insertstr = [bar2 stringByReplacingOccurrencesOfString:@"\\\"" withString:@"'"];
          
            [[DataBaseManager dataBaseManager]executeRecordsWithQuery:insertstr withArguments:deletesArray];
        }
        
       
        
    }else if (connection == CategoryConnection){
        
        NSString *responseStr = [[NSString alloc] initWithBytes:[CatresponseData mutableBytes] length:[CatresponseData length] encoding:NSUTF8StringEncoding];
        
        NSError *error;
        dataDict=[[NSMutableDictionary alloc] init];
        NSData *jsonData = [responseStr dataUsingEncoding:NSUTF8StringEncoding];
        dataDict =[NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
        //NSLog(@"%@",dataDict);
        
        NSMutableArray *deleteArray=[dataDict objectForKey:@"delete-queries"];
        NSMutableArray *insertsArray=[dataDict objectForKey:@"insert-queries"];
        NSMutableArray *deletesArray;
        for (int i=0; i<[deleteArray count]; i++)
        {
            NSString *foo=[deleteArray objectAtIndex:i];
            NSString* bar = [foo stringByReplacingOccurrencesOfString:@"'" withString:@"\""];
            NSString* deletestr = [bar stringByReplacingOccurrencesOfString:@"\\\"" withString:@"'"];
            [[DataBaseManager dataBaseManager]executeRecordsWithQuery:deletestr withArguments:deletesArray];
            
            NSString *foo2=[insertsArray objectAtIndex:i];
            NSString* bar2 = [foo2 stringByReplacingOccurrencesOfString:@"'" withString:@"\""];
            NSString* insertstr = [bar2 stringByReplacingOccurrencesOfString:@"\\\"" withString:@"'"];
           [[DataBaseManager dataBaseManager]executeRecordsWithQuery:insertstr withArguments:deletesArray];
        }
    
    }else if (connection == EditConnection){
        
        NSString *responseStr = [[NSString alloc] initWithBytes:[EditResponseData mutableBytes] length:[EditResponseData length] encoding:NSUTF8StringEncoding];
        
        NSError *error;
        dataDict=[[NSMutableDictionary alloc] init];
        NSData *jsonData = [responseStr dataUsingEncoding:NSUTF8StringEncoding];
        dataDict =[NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
        ////NSLog(@"%@",dataDict);
        NSString *insertstr=[[dataDict objectForKey:@"response"] objectForKey:@"update-string"];
    
        NSMutableArray *misUpdatearray=[[NSMutableArray alloc]init];
        [[DataBaseManager dataBaseManager] executeRecordsWithQuery:insertstr withArguments:misUpdatearray];
    }
}

-(void)Cancelprofile
{
    
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

{
    if (toInterfaceOrientation==UIInterfaceOrientationLandscapeRight||toInterfaceOrientation==UIInterfaceOrientationLandscapeLeft) {
        isLandScope=YES;
        
    }
    else
    {
        isLandScope=NO;
    }
    [self updateUI];
}
-(void)updateUI
{
    
    if (isLandScope)
    {
        
        CGFloat width,height;
        
        width=1024;
        height=748;
        backgroundcolorview.frame=CGRectMake(0,y,width,height-100);
        
        
        sidemenu.frame=CGRectMake(0, 1,170 ,height-150);
        //sidemenu.hidden=YES;
        
        [categorybutton setFrame:CGRectMake(0.0,p,170,40)];
        navBar.frame=CGRectMake(0, 0,width , 50.0);
        [logoBtn setFrame:CGRectMake(60,0,250,50)];
        
        sationLbl.frame=CGRectMake(navBar.frame.size.width-280, 5,100, 40);
        EmpIdlbl.frame=CGRectMake(navBar.frame.size.width-193, 5,150, 40);
        Timelbl.frame=CGRectMake(navBar.frame.size.width-62, 6,80, 40);
        
        
        mainview.frame=CGRectMake(20,60,width-40,height-200);
          maintoolBar.frame = CGRectMake(0, 0, mainview.frame.size.width, 40);
          profiledataScrollview.frame=CGRectMake(0, 40,mainview.frame.size.width, mainview.frame.size.height-(maintoolBar.frame.size.height));
      CGFloat labelwidth=(profiledataScrollview.frame.size.width/4);
        profiledataScrollview.contentSize=CGSizeMake(300,mainview.frame.size.height+150);
        
        int k=20;
        for (int i=0; i<9; i++)
        {
            UILabel *mylabel=(UILabel *)[profiledataScrollview viewWithTag:i+100];
            mylabel.frame=CGRectMake(labelwidth-30, k, labelwidth+60, 40);
            [profiledataScrollview addSubview:mylabel];
            
            UITextField *mytextfield=(UITextField *)[profiledataScrollview viewWithTag:i+100];
            mytextfield.frame=CGRectMake(labelwidth+textLabel.frame.size.width-20, k,labelwidth, 40);
          [profiledataScrollview addSubview:mytextfield];
            k=k+60;
        }
        //textLabel.frame=CGRectMake(labelwidth-30, p, labelwidth+60, 40);
        
        
        //dataField.frame=;
        
        saveprofiledataBtn.frame=CGRectMake(labelwidth+80,profiledataScrollview.frame.size.height+40, 100, 30);
        cancelProfiledata.frame=CGRectMake(labelwidth+260, profiledataScrollview.frame.size.height+40, 100, 30);

        [menubutton setFrame:CGRectMake(0,0,50,50)];
        
        
        
        logoimageview.frame=CGRectMake(50, (backgroundcolorview.frame.size.height)+5+y,(height-(backgroundcolorview.frame.size.height)-30), (height-(backgroundcolorview.frame.size.height)-30));
        
        [helpiconButton setFrame:CGRectMake(width-180,(backgroundcolorview.frame.size.height)+10+y,70,70)];
        
        
        [logouticonButton setFrame:CGRectMake(width-100,(backgroundcolorview.frame.size.height)+10+y,70,70)];
        
    
//Edit Password View
        
        EditPasswordBackView.frame=CGRectMake(10, maintoolBar.frame.size.height+10, (mainview.frame.size.width)-20, (mainview.frame.size.height)-(maintoolBar.frame.size.height+20));
       
        EditPasswordView.frame=CGRectMake(10, 10, EditPasswordBackView.frame.size.width-20, EditPasswordBackView.frame.size.height-20);
        EditPasswordView.contentSize=CGSizeMake( EditPasswordBackView.frame.size.width-20, EditPasswordBackView.frame.size.height+100);
       
        
        CGFloat editw=EditPasswordView.frame.size.width/4;
       
        Oldpasswordlbl.frame=CGRectMake(editw-30,20, editw, 40);
     
        OldpwdField.frame=CGRectMake(editw+Oldpasswordlbl.frame.size.width-20, 20,editw+60, 40);
      
        newpwdlbl.frame=CGRectMake(editw-30,80, editw, 40);
      
        NewpwdField.frame=CGRectMake(editw+Oldpasswordlbl.frame.size.width-20, 80,editw+60, 40);
      
        ConfirmPasswordlbl.frame=CGRectMake(editw-70,140, editw+50, 40);
        
        ConfirmPwdField.frame=CGRectMake(editw+Oldpasswordlbl.frame.size.width-20, 140,editw+60, 40);
        
        SaveEditPwdBtn.frame=CGRectMake(editw+editw/2, 240, 80, 30);
        
        CancelEditpwdBtn.frame=CGRectMake(editw+100+editw/2, 240, 80, 30);

//View profile view
        
        ViewProfiledatabackView.frame=CGRectMake(10, maintoolBar.frame.size.height+10, (mainview.frame.size.width)-20, (mainview.frame.size.height)-(maintoolBar.frame.size.height+20));
      
            ProfileDataTable.frame=CGRectMake(10, 10, ViewProfiledatabackView.frame.size.width-20, ViewProfiledatabackView.frame.size.height-20);
        
            //ProfileDataTable.frame=CGRectMake(10, 50, ViewProfiledatabackView.frame.size.width-20, ViewProfiledatabackView.frame.size.height-200);
        
//Edit profile view
        
        EditProfileBackView.frame=CGRectMake(10, maintoolBar.frame.size.height+10, (mainview.frame.size.width)-20, (mainview.frame.size.height)-(maintoolBar.frame.size.height+20));
        
        EditProfileView.frame=CGRectMake(10, 10, EditProfileBackView.frame.size.width-20, EditProfileBackView.frame.size.height-20);
        EditProfileView.contentSize=CGSizeMake(EditProfileBackView.frame.size.width-20, EditProfileBackView.frame.size.height+200);
        
        
        CGFloat Profilewidth=(EditProfileView.frame.size.width/4);
        
        useridlbl.frame=CGRectMake(Profilewidth-50, 20, Profilewidth+20, 40);
        useridField.frame=CGRectMake(Profilewidth+useridlbl.frame.size.width-40, 20,Profilewidth+100, 40);
        Firstnamelbl.frame=CGRectMake(Profilewidth-50,80, Profilewidth+20, 40);
        FirstnameField.frame=CGRectMake(Profilewidth+useridlbl.frame.size.width-40, 80,Profilewidth+100, 40);
        lastnamelbl.frame=CGRectMake(Profilewidth-50,140, Profilewidth+20, 40);
        
        lastnameField.frame=CGRectMake(Profilewidth+useridlbl.frame.size.width-40,140,Profilewidth+100, 40);
      
        phnumberlbl.frame=CGRectMake(Profilewidth-50,200, Profilewidth+20, 40);
      
        PhnumberField.frame=CGRectMake(Profilewidth+useridlbl.frame.size.width-40, 200,Profilewidth+100, 40);
        emaillbl.frame=CGRectMake(Profilewidth-50,260, Profilewidth+20, 40);
       
        EmailField.frame=CGRectMake(Profilewidth+useridlbl.frame.size.width-40, 260,Profilewidth+100, 40);
        
        addresslbl.frame=CGRectMake(Profilewidth-50,320, Profilewidth+20, 40);
      
        addressField.frame=CGRectMake(Profilewidth+useridlbl.frame.size.width-40, 320,Profilewidth+100, 40);
    
        SaveEditprofileBtn.frame=CGRectMake(Profilewidth+Profilewidth/2+60,400, 100, 30);
        
    }
    else
    {
        CGFloat width,height;
        height=1004;
        width=768;
        //NSLog(@" %f,%f",width,height);
        
        
        backgroundcolorview.frame=CGRectMake(0,y,width,height-100);
        navBar.frame=CGRectMake(0, 0,width , 50.0);
        [logoBtn setFrame:CGRectMake(60,0,250,50)];
        
        
        sationLbl.frame=CGRectMake(navBar.frame.size.width-280, 5,100, 40);
        EmpIdlbl.frame=CGRectMake(navBar.frame.size.width-193, 5,150, 40);
        Timelbl.frame=CGRectMake(navBar.frame.size.width-62, 6,80, 40);
        
        
        sidemenu.frame=CGRectMake(0, 1,170 ,height-150);
        // sidemenu.hidden=YES;
        [categorybutton setFrame:CGRectMake(0.0,p,170,40)];
        mainview.frame=CGRectMake(20,60,width-40,height-200);
        [menubutton setFrame:CGRectMake(0,0,50,50)];
          maintoolBar.frame = CGRectMake(0, 0, mainview.frame.size.width, 40);
         profiledataScrollview.frame=CGRectMake(0, 40,mainview.frame.size.width, mainview.frame.size.height-(maintoolBar.frame.size.height));
     CGFloat labelwidth=(profiledataScrollview.frame.size.width/4);
        profiledataScrollview.contentSize=CGSizeMake(300,mainview.frame.size.height+50);
        //textLabel.frame=CGRectMake(labelwidth-30, p, labelwidth+60, 40);
       int k=20;
        for (int i=0; i<9; i++)
        {
            UILabel *mylabel=(UILabel *)[profiledataScrollview viewWithTag:i+100];
            mylabel.frame=CGRectMake(labelwidth-30, k, labelwidth+60, 40);
            [profiledataScrollview addSubview:mylabel];
            
            UITextField *mytextfield=(UITextField *)[profiledataScrollview viewWithTag:i+100];
            mytextfield.frame=CGRectMake(labelwidth+textLabel.frame.size.width-20, k,labelwidth, 40);
            
              [profiledataScrollview addSubview:mytextfield];
            k=k+60;
            
        }
        
        
    
        //dataField.frame=CGRectMake(labelwidth+textLabel.frame.size.width-20, p,labelwidth, 40);

     saveprofiledataBtn.frame=CGRectMake(labelwidth+40,profiledataScrollview.frame.size.height-220, 100, 30);
     cancelProfiledata.frame=CGRectMake(labelwidth+220, profiledataScrollview.frame.size.height-220, 100, 30);
        //downtoolBar.frame = CGRectMake(0, 0, mainview.frame.size.width, 40);
        
        logoimageview.frame=CGRectMake(50, (backgroundcolorview.frame.size.height)+5+y,(height-(backgroundcolorview.frame.size.height)-30), (height-(backgroundcolorview.frame.size.height)-30));
        
        [helpiconButton setFrame:CGRectMake(width-180,(backgroundcolorview.frame.size.height)+10+y,70,70)];
        
        
        [logouticonButton setFrame:CGRectMake(width-100,(backgroundcolorview.frame.size.height)+10+y,70,70)];
        
        
//Edit Password View
        
        EditPasswordBackView.frame=CGRectMake(10, maintoolBar.frame.size.height+10, (mainview.frame.size.width)-20, (mainview.frame.size.height)-(maintoolBar.frame.size.height+20));
        
        EditPasswordView.frame=CGRectMake(10, 10, EditPasswordBackView.frame.size.width-20, EditPasswordBackView.frame.size.height-20);
        EditPasswordView.contentSize=CGSizeMake( EditPasswordBackView.frame.size.width-20, EditPasswordBackView.frame.size.height+100);
        
        
        CGFloat editw=EditPasswordView.frame.size.width/4;
        
        Oldpasswordlbl.frame=CGRectMake(editw-30,20, editw, 40);
        
        OldpwdField.frame=CGRectMake(editw+Oldpasswordlbl.frame.size.width-20, 20,editw+60, 40);
        
        newpwdlbl.frame=CGRectMake(editw-30,80, editw, 40);
        
        NewpwdField.frame=CGRectMake(editw+Oldpasswordlbl.frame.size.width-20, 80,editw+60, 40);
        
        ConfirmPasswordlbl.frame=CGRectMake(editw-70,140, editw+50, 40);
        
        ConfirmPwdField.frame=CGRectMake(editw+Oldpasswordlbl.frame.size.width-20, 140,editw+60, 40);
        
        SaveEditPwdBtn.frame=CGRectMake(editw+editw/2, 240, 80, 30);
        
        CancelEditpwdBtn.frame=CGRectMake(editw+100+editw/2, 240, 80, 30);
        
//View profile view
        
        ViewProfiledatabackView.frame=CGRectMake(10, maintoolBar.frame.size.height+10, (mainview.frame.size.width)-20, (mainview.frame.size.height)-(maintoolBar.frame.size.height+20));
        
        //ProfileDataTable.frame=CGRectMake(10, 10, ViewProfiledatabackView.frame.size.width-20, ViewProfiledatabackView.frame.size.height-20);
        
        ProfileDataTable.frame=CGRectMake(10, 50, ViewProfiledatabackView.frame.size.width-20, ViewProfiledatabackView.frame.size.height-200);
        
        
//Edit profile view
        
        EditProfileBackView.frame=CGRectMake(10, maintoolBar.frame.size.height+10, (mainview.frame.size.width)-20, (mainview.frame.size.height)-(maintoolBar.frame.size.height+20));
        
        EditProfileView.frame=CGRectMake(10, 10, EditProfileBackView.frame.size.width-20, EditProfileBackView.frame.size.height-20);
        EditProfileView.contentSize=CGSizeMake(EditProfileBackView.frame.size.width-20, EditProfileBackView.frame.size.height+200);
        
        
        CGFloat Profilewidth=(EditProfileBackView.frame.size.width/4);
        
        useridlbl.frame=CGRectMake(Profilewidth-50, 20, Profilewidth+20, 40);
        useridField.frame=CGRectMake(Profilewidth+useridlbl.frame.size.width-40, 20,Profilewidth+100, 40);
        Firstnamelbl.frame=CGRectMake(Profilewidth-50,80, Profilewidth+20, 40);
        FirstnameField.frame=CGRectMake(Profilewidth+useridlbl.frame.size.width-40, 80,Profilewidth+100, 40);
        lastnamelbl.frame=CGRectMake(Profilewidth-50,140, Profilewidth+20, 40);
        
        lastnameField.frame=CGRectMake(Profilewidth+useridlbl.frame.size.width-40,140,Profilewidth+100, 40);
        
        phnumberlbl.frame=CGRectMake(Profilewidth-50,200, Profilewidth+20, 40);
        
        PhnumberField.frame=CGRectMake(Profilewidth+useridlbl.frame.size.width-40, 200,Profilewidth+100, 40);
        emaillbl.frame=CGRectMake(Profilewidth-50,260, Profilewidth+20, 40);
        
        EmailField.frame=CGRectMake(Profilewidth+useridlbl.frame.size.width-40, 260,Profilewidth+100, 40);
        
        addresslbl.frame=CGRectMake(Profilewidth-50,320, Profilewidth+20, 40);
        
        addressField.frame=CGRectMake(Profilewidth+useridlbl.frame.size.width-40, 320,Profilewidth+100, 40);
        
        SaveEditprofileBtn.frame=CGRectMake(Profilewidth+Profilewidth/2+60,400, 100, 30);
        
    }
    
}


-(void)menuclicked
{
    if (menuslected == false)
    {
        
        //NSLog(@"called");
        //NSLog(@"%d",menuslected);
        menuslected=YES;
        
        
//        [UIView beginAnimations:nil context:NULL];
//        [UIView setAnimationDuration:1.0f];
        sidemenu.transform = CGAffineTransformMakeTranslation(0,0);
        //[SideMenuView setBackgroundColor:[UIColor whiteColor]];
        //sidemenu.hidden=NO;
 //       [UIView commitAnimations];
        [backgroundcolorview addSubview:sidemenu];
        
       // [UIView beginAnimations:nil context:NULL];
       // [UIView setAnimationDuration:0.9f];
        menubutton.transform = CGAffineTransformMakeTranslation(180,0);
        
        menubutton.transform = CGAffineTransformRotate( menubutton.transform, - M_PI);
      //  [UIView commitAnimations];
     //   [UIView beginAnimations:nil context:NULL];
      //  [UIView setAnimationDuration:1.0f];
        logoBtn.hidden=YES;
        
        
    }else
    {
        
        menuslected=NO;
        
//        [UIView beginAnimations:nil context:NULL];
//        [UIView setAnimationDuration:1.0f];
        sidemenu.transform = CGAffineTransformMakeTranslation(-250,0);
        
      //  [UIView commitAnimations];
        
        
        
        
//        [UIView beginAnimations:nil context:NULL];
//        [UIView setAnimationDuration:1.0f];
        menubutton.transform = CGAffineTransformMakeTranslation(0,0);
        
        
//        [UIView commitAnimations];
//        [UIView beginAnimations:nil context:NULL];
//        [UIView setAnimationDuration:1.0f];
         logoBtn.hidden=NO;
        
    }
    
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    
    
//    [UIView beginAnimations:nil context:NULL];
//    [UIView setAnimationDuration:0.8f];
    mainview.transform = CGAffineTransformMakeTranslation(0,0);
    
    
//    [UIView commitAnimations];
//    [UIView beginAnimations:nil context:NULL];
//    [UIView setAnimationDuration:0.8f];
    sidemenu.transform = CGAffineTransformMakeTranslation(-250,0);
    //[SideMenuView setBackgroundColor:[UIColor whiteColor]];
    
//    [UIView commitAnimations];
//    [UIView commitAnimations];
//    [UIView beginAnimations:nil context:NULL];
//    [UIView setAnimationDuration:0.0f];
    menubutton.transform = CGAffineTransformMakeTranslation(0,0);
    
    
//    [UIView commitAnimations];
//    [UIView beginAnimations:nil context:NULL];
//    [UIView setAnimationDuration:0.0f];
    menuslected=NO;
     logoBtn.hidden=NO;
}


-(void)helpiconclicked
{
    
}
-(void)logoutButtonClicked
{
       [serverSyncClassObject LogoutMethod];
    
    NSString *updateSQL =@"UPDATE miscellaneous SET userType=?,sessionId=?,userID=?";
    NSMutableArray *misUpdatearray=[[NSMutableArray alloc]initWithObjects:@"",@"",@"", nil];
    [[DataBaseManager dataBaseManager] executeRecordsWithQuery:updateSQL withArguments:misUpdatearray];
    [self.navigationController popToRootViewControllerAnimated:NO];
    [self releaseViews];
    [generalDataObject  releasevariable];
    
}

-(void)categotybuttonclicked:(UIButton *)sender
{
    NSArray *viewS = [self.navigationController viewControllers];
    //NSLog(@"nav views %@",viewS);
    NSInteger selectedrow=sender.tag;
    if(selectedrow == 0){
        
        Home *homeview=[[Home alloc]initWithNibName:@"Home" bundle:Nil];
        NSString *returnvalue;
        NSInteger selectedview;
        for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
        {
            if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Home class]])
            {
                returnvalue=@"yes";
                selectedview=m;
                break;
            }
            
        }
        ////NSLog(@"%d",selectedview);
        if([returnvalue isEqualToString:@"yes"])
        {
            [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
            [self releaseViews];
        }else{
            
            [self.navigationController pushViewController:homeview animated:NO];
            [self releaseViews];
        }
        
    }else if(selectedrow == 5){
        if ([[generalDataObject  userType] isEqualToString:@"employee"])
        {
            if ([[generalDataObject  settings_permission] isEqualToString:@"yes"])
            {
                [sender setImage:[UIImage imageNamed:@"settingsactive2.png"] forState:UIControlStateNormal];
                NSString *returnvalue;
                NSInteger selectedview;
               Settings  *settingsview=[[Settings alloc]initWithNibName:@"Settings" bundle:Nil];
                for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
                {
                    if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Settings class]])
                    {
                        returnvalue=@"yes";
                        selectedview=m;
                        break;
                    }
                    
                }
                if([returnvalue isEqualToString:@"yes"])
                {
                    [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
                    [self releaseViews];
                }else
                {
                   
                    [self.navigationController pushViewController:settingsview animated:NO];
                    [self releaseViews];
                }
                
            }else{
                
                UIAlertView *authalert=[[UIAlertView alloc]initWithTitle:@"Authentication:" message:@"User not authenticated" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
                
                [authalert show];
            }
        }else{
            [sender setImage:[UIImage imageNamed:@"settingsactive2.png"] forState:UIControlStateNormal];
            NSString *returnvalue;
            NSInteger selectedview;
            Settings  *settingsview=[[Settings alloc]initWithNibName:@"Settings" bundle:Nil];
            for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
            {
                if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Settings class]])
                {
                    returnvalue=@"yes";
                    selectedview=m;
                    break;
                }
                
            }
            if([returnvalue isEqualToString:@"yes"])
            {
                [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
                [self releaseViews];
            }else
            {
                [self.navigationController pushViewController:settingsview animated:NO];
                [self releaseViews];
            }
            
            
        }
        
        
    }else if(selectedrow == 8){
        NSString *returnvalue;
        NSInteger selectedview;
        Stores *storesview=[[Stores alloc]initWithNibName:@"Stores" bundle:Nil];
        for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
        {
            if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Stores class]])
            {
                returnvalue=@"yes";
                selectedview=m;
                break;
            }
            
        }
        if([returnvalue isEqualToString:@"yes"])
        {
            [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
            [self releaseViews];
        }else
        {
            
            [self.navigationController pushViewController:storesview animated:NO];
            [self releaseViews];
        }
        
    }else if(selectedrow == 2){
        
        if ([[generalDataObject  userType] isEqualToString:@"employee"])
        {
            if ([[generalDataObject  inventory_permission] isEqualToString:@"yes"])
            {
                NSString *returnvalue;
                NSInteger selectedview;
                Inventory *inventoryview=[[Inventory alloc]initWithNibName:@"Inventory" bundle:Nil];
                for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
                {
                    if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Inventory class]])
                    {
                        returnvalue=@"yes";
                        selectedview=m;
                        break;
                    }
                    
                }
                if([returnvalue isEqualToString:@"yes"])
                {
                    [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
                    [self releaseViews];
                }else
                {
                    
                    [self.navigationController pushViewController:inventoryview animated:NO];
                    [self releaseViews];
                }
                
            }else{
                
                UIAlertView *authalert=[[UIAlertView alloc]initWithTitle:@"Authentication:" message:@"User not authenticated" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
                
                [authalert show];
            }
        }
        else
        {
            
            NSString *returnvalue;
            NSInteger selectedview;
            Inventory *inventoryview=[[Inventory alloc]initWithNibName:@"Inventory" bundle:Nil];
            for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
            {
                if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Inventory class]])
                {
                    returnvalue=@"yes";
                    selectedview=m;
                    break;
                }
                
            }
            if([returnvalue isEqualToString:@"yes"])
            {
                [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
                [self releaseViews];
            }else
            {
                
                [self.navigationController pushViewController:inventoryview animated:NO];
                [self releaseViews];
            }
        }
    }else if(selectedrow == 3){
        
        if ([[generalDataObject  userType] isEqualToString:@"employee"])
        {
            if ([[generalDataObject  customer_permission] isEqualToString:@"yes"])
            {
                NSString *returnvalue;
                NSInteger selectedview;
                Customers *customersview=[[Customers alloc]initWithNibName:@"Customers" bundle:Nil];
                for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
                {
                    if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Customers class]])
                    {
                        returnvalue=@"yes";
                        selectedview=m;
                        break;
                    }
                    
                }
                if([returnvalue isEqualToString:@"yes"])
                {
                    [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
                    [self releaseViews];
                }else
                {
                    
                    [self.navigationController pushViewController:customersview animated:NO];
                    [self releaseViews];
                }
                
            }else{
                
                UIAlertView *authalert=[[UIAlertView alloc]initWithTitle:@"Authentication:" message:@"User not authenticated" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
                
                [authalert show];
            }
        }else{
            
            NSString *returnvalue;
            NSInteger selectedview;
            Customers *customersview=[[Customers alloc]initWithNibName:@"Customers" bundle:Nil];
            for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
            {
                if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Customers class]])
                {
                    returnvalue=@"yes";
                    selectedview=m;
                    break;
                }
                
            }
            if([returnvalue isEqualToString:@"yes"])
            {
                [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
                [self releaseViews];
            }else
            {
                
                [self.navigationController pushViewController:customersview animated:NO];
                [self releaseViews];
            }
        }
        
    }else if(selectedrow == 4){
        if ([[generalDataObject  userType] isEqualToString:@"admin"])
        {
            NSString *returnvalue;
            NSInteger selectedview;
            Employees *employeesview=[[Employees alloc]initWithNibName:@"Employees" bundle:Nil];
            for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
            {
                if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Employees class]])
                {
                    returnvalue=@"yes";
                    selectedview=m;
                    break;
                }
                
            }
            if([returnvalue isEqualToString:@"yes"])
            {
                [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
                [self releaseViews];
            }else
            {
                
                [self.navigationController pushViewController:employeesview animated:NO];
                [self releaseViews];
            }
            
        }else{
            UIAlertView *authalert=[[UIAlertView alloc]initWithTitle:@"Authentication:" message:@"User not authenticated" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
            
            [authalert show];
        }
        
    }else if(selectedrow == 6){
        
        if ([[generalDataObject  userType] isEqualToString:@"employee"])
        {
            if ([[generalDataObject  settings_permission] isEqualToString:@"yes"])
            {
                NSString *returnvalue;
                NSInteger selectedview;
                Reports *reportsview=[[Reports alloc]initWithNibName:@"Reports" bundle:Nil];
                for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
                {
                    if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Reports class]])
                    {
                        returnvalue=@"yes";
                        selectedview=m;
                        break;
                    }
                    
                }
                if([returnvalue isEqualToString:@"yes"])
                {
                    [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
                    [self releaseViews];
                }else
                {
                    
                    [self.navigationController pushViewController:reportsview animated:NO];
                    [self releaseViews];
                }
                
            }else{
                
                UIAlertView *authalert=[[UIAlertView alloc]initWithTitle:@"Authentication:" message:@"User not authenticated" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
                
                [authalert show];
            }
        }else{
            
            NSString *returnvalue;
            NSInteger selectedview;
            Reports *reportsview=[[Reports alloc]initWithNibName:@"Reports" bundle:Nil];
            for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
            {
                if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Reports class]])
                {
                    returnvalue=@"yes";
                    selectedview=m;
                    break;
                }
                
            }
            if([returnvalue isEqualToString:@"yes"])
            {
                [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
                [self releaseViews];
            }else
            {
                
                [self.navigationController pushViewController:reportsview animated:NO];
                [self releaseViews];
            }
            
        }
        
    }else if(selectedrow == 7){
        NSString *returnvalue;
        NSInteger selectedview;
        Contacts *contactsview=[[Contacts alloc]initWithNibName:@"Contacts" bundle:Nil];
        for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
        {
            if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Contacts class]])
            {
                returnvalue=@"yes";
                selectedview=m;
                break;
            }
            
        }
        if([returnvalue isEqualToString:@"yes"])
        {
            [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
            [self releaseViews];
        }else
        {
            
            [self.navigationController pushViewController:contactsview animated:NO];
            [self releaseViews];
        }

    }
 
    
}



- (NSUInteger)supportedInterfaceOrientations // iOS 6 autorotation fix
{
    return UIInterfaceOrientationMaskAll;
}

-(void)releaseViews
{
    NSArray *mainArray = self.view.subviews;
    for (int i = 0; i<[mainArray count]; i++) {
        UIView *vi =[mainArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    
    NSArray *sideArray = sidemenu.subviews;
    for (int i = 0; i<[sideArray count]; i++) {
        UIView *vi =[sideArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    
    NSArray *navBarArray = navBar.subviews;
    for (int i = 0; i<[navBarArray count]; i++) {
        UIView *vi =[navBarArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }

    [sidemenu removeFromSuperview],[mainview removeFromSuperview],[backgroundcolorview removeFromSuperview];
    sidemenu= nil,mainview= nil,backgroundcolorview= nil;
    categorybutton= nil;
    [logobackview removeFromSuperview],[logoimageview removeFromSuperview];
    
    logobackview= nil,logoimageview= nil;
    helpiconButton= nil,logouticonButton= nil,menubutton= nil;
    backButton3= nil,backButton2= nil,backButton= nil;
    navBar= nil;
    
    saveprofiledataBtn= nil,cancelProfiledata= nil;
    
    textLabel= nil;
    dataField= nil;
    profiledataScrollview= nil;
    Emailid= nil,userid= nil,password= nil,firstname= nil,lastname= nil,middlename= nil,phonenumber= nil,address= nil,confirmpassword= nil;
    maintoolBar= nil;
    JsonSendDataDict= nil;
    [admindataArray removeAllObjects];
    admindataArray= nil;
    connection1= nil,CategoryConnection= nil,EditConnection= nil;
    responseData= nil,CatresponseData= nil,EditResponseData= nil;
    dataDict= nil;
    
    EditProfileBtn= nil,ViewProfileBtn= nil,EditPassWordBtn= nil;
    
    //Edit Password View
    NSArray *EditPasswordViewArray = EditPasswordView.subviews;
    for (int i = 0; i<[EditPasswordViewArray count]; i++) {
        UIView *vi =[EditPasswordViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    
    NSArray *EditPasswordBackViewArray = EditPasswordBackView.subviews;
    for (int i = 0; i<[EditPasswordBackViewArray count]; i++) {
        UIView *vi =[EditPasswordBackViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    
    [EditPasswordView removeFromSuperview],[EditPasswordBackView removeFromSuperview];
    EditPasswordBackView= nil;
    EditPasswordView= nil;
    Oldpasswordlbl= nil,newpwdlbl= nil,ConfirmPasswordlbl= nil;
    OldpwdField= nil,NewpwdField= nil,ConfirmPwdField= nil;
    SaveEditPwdBtn= nil,CancelEditpwdBtn= nil;
    //View profile data view
    ViewProfiledatabackView= nil;
    ProfileDataTable= nil;
   
    allkeysArray= nil,AllvaluesArray= nil;
    
    //Edit profile view
    NSArray *EditProfileBackViewArray = EditProfileBackView.subviews;
    for (int i = 0; i<[EditProfileBackViewArray count]; i++) {
        UIView *vi =[EditProfileBackViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    
    NSArray *EditProfileViewArray = EditProfileView.subviews;
    for (int i = 0; i<[EditProfileViewArray count]; i++) {
        UIView *vi =[EditProfileViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [EditProfileView removeFromSuperview],[EditProfileBackView removeFromSuperview];
    EditProfileBackView= nil;
     EditProfileView= nil;
    Editprofilelbl= nil;
    editProfileField= nil;
    SaveEditprofileBtn= nil,CancelEditprofileBtn= nil;
    useridlbl= nil,Firstnamelbl= nil,lastnamelbl= nil,emaillbl= nil,phnumberlbl= nil,addresslbl= nil;
    useridField= nil,FirstnameField= nil,lastnameField= nil,EmailField= nil,PhnumberField= nil,addressField= nil;
    Unique_id= nil,Newpassword= nil;
    
    
    sationLbl= nil,Timelbl= nil,EmpIdlbl= nil;
    logoBtn= nil;
    [self.view removeFromSuperview];
    self.view = nil;

}

- (void)didReceiveMemoryWarning
{
    NSArray *viewS = [self.navigationController viewControllers];
    [self.navigationController popToViewController:[viewS objectAtIndex:1] animated:YES];
    [self releaseViews];
    
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
